Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Accediendo a la tabla n y contando filas con el titiritero en el error de javascript: "no se pudo encontrar el selector de coincidencia de elementos" tabla: n de tipo (2)> tr ""

Estoy tratando de contar mediante programación las filas en las tablas de la página https://rarity.tools/upcoming/ en javascript. Dado que el sitio se carga a través de javascript, he estado usando titiritero. El sitio tiene varias tablas (4 en total) y me gustaría poder hacer referencia a cada tabla y verificar cuántas filas tienen.

Intenté usar nth-of-type para seleccionar la segunda, tercera y cuarta tabla, pero recibo el error:

"Error: Error: no se pudo encontrar el selector de coincidencia de elementos "tabla: enésima de tipo (2)> tr""

Eliminar > tr devuelve un error similar:

"Error: Error: no se pudo encontrar el selector de coincidencia de elementos "tabla: enésima de tipo (2)""

También he intentado usar nth-child.

Código:

 const puppeteer = require('puppeteer'); let fetch = async () => { try { // Puppeteer initialization const browser = await puppeteer.launch({ headless: true, defaultViewport: null }); const [page] = await browser.pages(); await page.goto('https://rarity.tools/upcoming/'); await page.waitForTimeout(2500) // Timeout so page can load actual content const numTables = await page.$$eval('table', el => el.length) - 1; // Rarity.tools has a table for each month of data. Each table must be looped through. // There is an extra table for upcoming "To Be Announced", there is a -1 to subtract that table from tables being looped through. for (let j = 1; j < numTables + 1; j++) { const tableLength = await page.$eval(`table:nth-of-type(${j}) > tr`, el => el.length) console.log(tableLength) } } catch (error) { console.log(error) } } fetch();

Utilizar lo siguiente en su lugar no devuelve un error, sino que devuelve 0 para la segunda y tercera tabla, aunque puedo ver que el HTML del sitio que estoy raspando tiene filas de tabla debajo de la segunda y tercera tabla.

 const tableLength = await page.$$eval(`table:nth-of-type(${j}) > tr`, el => el.length)

Sin embargo, el código anterior con $$eval devuelve el valor correcto para la primera tabla.

Por favor, hágamelo saber si necesito proporcionar más información.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!